package com.damuzee.system.admin.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.mybatis.sql.exception.AutoKeyNullException;
import org.mybatis.sql.page.Page;
import org.springframework.stereotype.Service;

import com.damuzee.system.admin.domain.AcctDetail;
import com.damuzee.system.admin.domain.AgentAcct;
import com.damuzee.system.admin.domain.CustInfo;
import com.damuzee.system.admin.persistence.AcctDetailMapper;
import com.damuzee.system.admin.persistence.AgentAcctMapper;
import com.damuzee.system.admin.persistence.CustInfoMapper;
import com.damuzee.system.admin.service.AgentAcctService;

@Service
public class AgentAcctServiceImpl implements AgentAcctService{

	public Page<AgentAcct> getAgentAcctList(Page< AgentAcct> page,  AgentAcct  agentAcct) {
		return agentAcctMapper.selectAgentAcctByPage(page,   agentAcct);
	}

	public void saveAgentAcct(CustInfo cust, AgentAcct acct) {
		if (cust.getId() == null) {
			custInfoMapper.save(cust);
			Long custId = cust.getIdKey() ;
			if (custId != null) {
				acct.setCustId(Integer.parseInt(custId.toString()));
			}else{
				throw new AutoKeyNullException("autokey is null");
			}
		}		
		agentAcctMapper.insert(acct);
	}
	
 
	public List<AgentAcct> getAgentAcctList(AgentAcct acct) {
		 
		return agentAcctMapper.selectAgentAcctList(acct);
	}


	public void updateAcct(AgentAcct agentAcct) {
		agentAcctMapper.update(agentAcct); 
	}
	
	public void saveAcctDetail(AcctDetail detail) {
		acctDetailMapper.save(detail);		
	}



	@Resource
	private AgentAcctMapper agentAcctMapper;
	@Resource
	private CustInfoMapper custInfoMapper ;
	@Resource
	private AcctDetailMapper acctDetailMapper ;
}
